//
//  AppDelegate.m
//  faceLooker
//
//  Created by yww on 2018/12/12.
//  Copyright © 2018年 yww. All rights reserved.
//

#import "AppDelegate.h"
#import "MYShowViewController.h"
#import <Bugly/Bugly.h>

@interface AppDelegate ()
@end
 
@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //加载页面为文字跑马灯展示。注释后就是诗词
    [Bugly startWithAppId:@"717aedef31"];
    self.window= [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor=[UIColor grayColor];
    MYShowViewController *showVc=[[MYShowViewController alloc]init];
    self.window.rootViewController=showVc;
    [self.window makeKeyAndVisible];
    
    //其目的是转化unicode的w非中文字节
    [NSDictionary jr_swizzleMethod:@selector(description) withMethod:@selector(my_description) error:nil];
    //设备网络监听
    [self reachabilityStatus];
    return YES;
     
}
- (void)reachabilityStatus{
    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        // 当网络状态改变时调用
        if ([FLGlobalTool sharedInstance].networkStatus > 0) {
            if (status <= 0) {
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [MBProgressHUD showError:@"网络已断开" toView:self.window];
                });
            }
        }
        [FLGlobalTool sharedInstance].networkStatus = status;
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:
                NSLog(@"未知网络");
                break;
            case AFNetworkReachabilityStatusNotReachable:
                NSLog(@"没有网络");
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                NSLog(@"手机自带网络");
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                NSLog(@"WIFI");
                break;
        }
    }];
    //开始监控
    [manager startMonitoring];
}


- (void)applicationWillResignActive:(UIApplication *)application {
    //注销注册
    NSLog(@"注销");
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
     [[NSNotificationCenter defaultCenter]postNotificationName:@"applicationDidEnterBackground" object:nil];
    NSLog(@"程序进入前台模式");
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    [[NSNotificationCenter defaultCenter]postNotificationName:@"applicationWillEnterForeground" object:nil];
    NSLog(@"程序进入后台模式");
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    NSLog(@"程序恢复激活");
}


- (void)applicationWillTerminate:(UIApplication *)application {
    NSLog(@"程序被杀死");
}

//横屏 竖直
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window{
    if (self.allowRotation == YES) {
//        NSLog(@"横屏");
        return UIInterfaceOrientationMaskLandscape;
    }else{
        //竖屏
//        NSLog(@"竖屏");
        return UIInterfaceOrientationMaskPortrait;
    }
}


@end
